﻿using System;
using System.Collections.Generic;
using System.Text;
using UMC.Web;
using UMC.WorkFlow;
using UMC.WorkFlow.Entities;

namespace UMC.WorkFlow.Form
{
    //[Apiumc("Form", Auth = WebAuthType.Guest, Desc = "流程UI表单")]
    //class FormFlow : UMC.Web.WebFlow
    //{
       
    //    public override WebActivity GetFirstActivity()
    //    {

    //        var taskForm =  DataFactory.Instance().TaskForm( this.Context.Request.Command );
    //        if (taskForm != null)
    //        {
    //            return new FormUIActivity(taskForm);
    //        }
    //        return WebActivity.Empty;
    //    }
    //}
    [Apiumc("WorkFlow", Auth = WebAuthType.Guest, Desc = "工作流")]
    class WorkFlow : UMC.Web.WebFlow
    {

        public override WebActivity GetFirstActivity()
        {
            var cmdIndex = this.Context.Request.Command.IndexOf('.');
            switch (cmdIndex > 0? this.Context.Request.Command.Substring(0,cmdIndex): this.Context.Request.Command)
            {
                case "DbProvider":
                    return new WorkFlowDbProviderActivity();
                case "Work":
                    return new WorkFlowWorkActivity();
                case  "Control":
                    {
                        var taskForm = DataFactory.Instance().TaskKey(this.Context.Request.Command.Substring(cmdIndex + 1));
                        if (taskForm != null)
                        {
                            return new ControlActivity(taskForm);
                        }
                        return WebActivity.Empty;
                    }
                case "Form":
                    {
                        var taskForm = DataFactory.Instance().TaskForm(this.Context.Request.Command.Substring(cmdIndex + 1));
                        if (taskForm != null)
                        {
                            return new FormUIActivity(taskForm);
                        }
                        else
                        {
                            return WebActivity.Empty;

                        }
                    }
            }
            return WebActivity.Empty;
        }
    }
}
